<script setup>
import { ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import { getOverviewApi } from "@/api/report";
import { ElMessage } from "element-plus";

const router = useRouter();

// 概览数据
const overviewData = ref({
  clueTotal: 0,
  clueWaitAllot: 0,
  clueWaitFollow: 0,
  clueFollowing: 0,
  clueFalse: 0,
  clueConvertBusiness: 0,
  businessTotal: 0,
  businessWaitAllot: 0,
  businessWaitFollow: 0,
  businessFollowing: 0,
  businessFalse: 0,
  businessConvertCustomer: 0,
});

// 加载概览数据
const loadOverviewData = async () => {
  try {
    const result = await getOverviewApi();
    if (result.code == 1) {
      overviewData.value = result.data;
    } else {
      ElMessage.error(result.msg || "获取数据失败");
    }
  } catch (error) {
    console.error("获取概览数据失败:", error);
    ElMessage.error("获取数据失败");
  }
};

// 快捷操作跳转
const handleQuickAction = (path) => {
  router.push(path);
};

onMounted(() => {
  loadOverviewData();
});
</script>

<template>
  <div class="home-container">
    <!-- 欢迎信息 -->
    <div class="welcome-section">
      <div class="welcome-content">
        <div class="pikachu-container">
          <div class="pikachu">⚡</div>
          <div class="sparkles">✨</div>
        </div>
        <h1 class="welcome-title">欢迎您,进入轻客管家系统</h1>
      </div>
    </div>

    <!-- 概览面板 -->
    <div class="overview-section">
      <!-- 线索概览 -->
      <div class="overview-panel">
        <h2 class="panel-title">线索概览</h2>
        <div class="data-grid">
          <div class="data-item clue-item-1">
            <div class="data-label">总线索数</div>
            <div class="data-value">{{ overviewData.clueTotal }}</div>
            <div class="data-icon">🔍</div>
          </div>
          <div class="data-item clue-item-2">
            <div class="data-label">待分配线索数</div>
            <div class="data-value">{{ overviewData.clueWaitAllot }}</div>
            <div class="data-icon">📋</div>
          </div>
          <div class="data-item clue-item-3">
            <div class="data-label">待跟进线索数</div>
            <div class="data-value">{{ overviewData.clueWaitFollow }}</div>
            <div class="data-icon">⏰</div>
          </div>
          <div class="data-item clue-item-4">
            <div class="data-label">跟进中线索数</div>
            <div class="data-value">{{ overviewData.clueFollowing }}</div>
            <div class="data-icon">🚀</div>
          </div>
          <div class="data-item clue-item-5">
            <div class="data-label">伪线索数</div>
            <div class="data-value">{{ overviewData.clueFalse }}</div>
            <div class="data-icon">❌</div>
          </div>
          <div class="data-item clue-item-6">
            <div class="data-label">转商机线索数</div>
            <div class="data-value">{{ overviewData.clueConvertBusiness }}</div>
            <div class="data-icon">💼</div>
          </div>
        </div>
      </div>

      <!-- 商机概览 -->
      <div class="overview-panel">
        <h2 class="panel-title">商机概览</h2>
        <div class="data-grid">
          <div class="data-item business-item-1">
            <div class="data-label">总商机数</div>
            <div class="data-value">{{ overviewData.businessTotal }}</div>
            <div class="data-icon">🎯</div>
          </div>
          <div class="data-item business-item-2">
            <div class="data-label">待分配商机数</div>
            <div class="data-value">{{ overviewData.businessWaitAllot }}</div>
            <div class="data-icon">📊</div>
          </div>
          <div class="data-item business-item-3">
            <div class="data-label">待跟进商机数</div>
            <div class="data-value">{{ overviewData.businessWaitFollow }}</div>
            <div class="data-icon">⏳</div>
          </div>
          <div class="data-item business-item-4">
            <div class="data-label">跟进中商机数</div>
            <div class="data-value">{{ overviewData.businessFollowing }}</div>
            <div class="data-icon">🔥</div>
          </div>
          <div class="data-item business-item-5">
            <div class="data-label">回收商机数</div>
            <div class="data-value">{{ overviewData.businessFalse }}</div>
            <div class="data-icon">♻️</div>
          </div>
          <div class="data-item business-item-6">
            <div class="data-label">转客户商机数</div>
            <div class="data-value">
              {{ overviewData.businessConvertCustomer }}
            </div>
            <div class="data-icon">👥</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 快捷操作模块 -->
    <div class="quick-actions-section">
      <div class="action-module" @click="handleQuickAction('/resource/course')">
        <div class="module-icon">
          <el-icon size="40"><Notebook /></el-icon>
        </div>
        <div class="module-title">课程管理</div>
        <div class="module-subtitle">课程信息维护</div>
      </div>

      <div
        class="action-module"
        @click="handleQuickAction('/resource/activity')"
      >
        <div class="module-icon">
          <el-icon size="40"><Calendar /></el-icon>
        </div>
        <div class="module-title">活动管理</div>
        <div class="module-subtitle">营销活动管理</div>
      </div>

      <div class="action-module" @click="handleQuickAction('/clue/list')">
        <div class="module-icon">
          <el-icon size="40"><Document /></el-icon>
        </div>
        <div class="module-title">线索管理</div>
        <div class="module-subtitle">潜在客户追踪</div>
      </div>

      <div class="action-module" @click="handleQuickAction('/business/list')">
        <div class="module-icon">
          <el-icon size="40"><Briefcase /></el-icon>
        </div>
        <div class="module-title">商机管理</div>
        <div class="module-subtitle">销售机会管理</div>
      </div>

      <div class="action-module" @click="handleQuickAction('/customer')">
        <div class="module-icon">
          <el-icon size="40"><User /></el-icon>
        </div>
        <div class="module-title">客户管理</div>
        <div class="module-subtitle">客户信息维护</div>
      </div>

      <div class="action-module" @click="handleQuickAction('/system/log')">
        <div class="module-icon">
          <el-icon size="40"><Memo /></el-icon>
        </div>
        <div class="module-title">日志统计</div>
        <div class="module-subtitle">系统操作日志</div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.home-container {
  padding: 30px;
  background: linear-gradient(135deg, #f5f7fa 0%, #e8f4fd 100%);
  min-height: 100vh;
  position: relative;
  overflow: hidden;
}

.home-container::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(
      circle at 20% 80%,
      rgba(255, 107, 107, 0.1) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 80% 20%,
      rgba(78, 205, 196, 0.1) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 40% 40%,
      rgba(69, 183, 209, 0.1) 0%,
      transparent 50%
    );
  animation: background-float 20s ease-in-out infinite;
  pointer-events: none;
}

@keyframes background-float {
  0%,
  100% {
    transform: translate(0, 0) scale(1);
  }
  25% {
    transform: translate(-10px, -10px) scale(1.1);
  }
  50% {
    transform: translate(10px, -5px) scale(0.9);
  }
  75% {
    transform: translate(-5px, 10px) scale(1.05);
  }
}

.welcome-section {
  text-align: center;
  margin-bottom: 40px;
  position: relative;
}

.welcome-content {
  position: relative;
  z-index: 2;
}

.pikachu-container {
  position: relative;
  margin-bottom: 20px;
}

.pikachu {
  font-size: 60px;
  animation: pikachu-bounce 2s ease-in-out infinite;
  display: inline-block;
  filter: drop-shadow(0 4px 8px rgba(255, 215, 0, 0.3));
}

.sparkles {
  position: absolute;
  top: -10px;
  right: -20px;
  font-size: 24px;
  animation: sparkle 1.5s ease-in-out infinite;
}

.welcome-title {
  font-size: 32px;
  background: linear-gradient(
    45deg,
    #ff6b6b,
    #4ecdc4,
    #45b7d1,
    #96ceb4,
    #feca57
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0;
  font-weight: 600;
  text-shadow: none;
  animation: rainbow-text 3s ease-in-out infinite;
}

.welcome-subtitle {
  font-size: 16px;
  color: #ff6b6b;
  margin-top: 10px;
  font-style: italic;
  animation: fade-in-up 1s ease-out;
}

@keyframes pikachu-bounce {
  0%,
  20%,
  50%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

@keyframes sparkle {
  0%,
  100% {
    opacity: 0;
    transform: scale(0.8) rotate(0deg);
  }
  50% {
    opacity: 1;
    transform: scale(1.2) rotate(180deg);
  }
}

@keyframes rainbow-text {
  0% {
    filter: hue-rotate(0deg);
  }
  100% {
    filter: hue-rotate(360deg);
  }
}

@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.overview-section {
  display: flex;
  gap: 40px;
  margin-bottom: 50px;
  max-width: 1600px;
  margin-left: auto;
  margin-right: auto;
}

.overview-panel {
  flex: 1;
  background-color: #fff;
  border-radius: 16px;
  padding: 40px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
}

.panel-title {
  font-size: 20px;
  color: #2c3e50;
  margin: 0 0 25px 0;
  font-weight: 600;
  text-align: center;
  position: relative;
}

.panel-title::after {
  content: "";
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 3px;
  background: linear-gradient(90deg, #409eff, #36cfc9);
  border-radius: 2px;
}

.data-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 25px;
}

.data-item {
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
  border-radius: 12px;
  padding: 25px;
  text-align: center;
  border: 1px solid #e9ecef;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.data-item::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #409eff, #36cfc9);
  transform: scaleX(0);
  transition: transform 0.3s ease;
}

.data-item:hover::before {
  transform: scaleX(1);
}

.data-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(64, 158, 255, 0.15);
}

.data-icon {
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 20px;
  opacity: 0.7;
  animation: icon-float 3s ease-in-out infinite;
}

/* 线索概览彩色样式 */
.clue-item-1 {
  border-left: 4px solid #ff6b6b;
}
.clue-item-2 {
  border-left: 4px solid #4ecdc4;
}
.clue-item-3 {
  border-left: 4px solid #45b7d1;
}
.clue-item-4 {
  border-left: 4px solid #96ceb4;
}
.clue-item-5 {
  border-left: 4px solid #feca57;
}
.clue-item-6 {
  border-left: 4px solid #ff9ff3;
}

/* 商机概览彩色样式 */
.business-item-1 {
  border-left: 4px solid #54a0ff;
}
.business-item-2 {
  border-left: 4px solid #5f27cd;
}
.business-item-3 {
  border-left: 4px solid #00d2d3;
}
.business-item-4 {
  border-left: 4px solid #ff9f43;
}
.business-item-5 {
  border-left: 4px solid #10ac84;
}
.business-item-6 {
  border-left: 4px solid #ee5a24;
}

@keyframes icon-float {
  0%,
  100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-3px);
  }
}

.data-label {
  font-size: 13px;
  color: #606266;
  margin-bottom: 12px;
  font-weight: 500;
}

.data-value {
  font-size: 28px;
  font-weight: 700;
  background: linear-gradient(135deg, #409eff, #36cfc9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.quick-actions-section {
  display: flex;
  gap: 20px;
  flex-wrap: nowrap;
  justify-content: center;
  max-width: 1400px;
  margin: 0 auto;
}

.action-module {
  width: 180px;
  height: 130px;
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.action-module:nth-child(1) {
  border-top: 4px solid #ff6b6b;
}
.action-module:nth-child(2) {
  border-top: 4px solid #4ecdc4;
}
.action-module:nth-child(3) {
  border-top: 4px solid #45b7d1;
}
.action-module:nth-child(4) {
  border-top: 4px solid #96ceb4;
}
.action-module:nth-child(5) {
  border-top: 4px solid #feca57;
}
.action-module:nth-child(6) {
  border-top: 4px solid #ff9ff3;
}

.action-module::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    rgba(64, 158, 255, 0.05),
    rgba(54, 207, 201, 0.05)
  );
  opacity: 0;
  transition: opacity 0.3s ease;
}

.action-module:hover::before {
  opacity: 1;
}

.action-module:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 40px rgba(64, 158, 255, 0.2);
}

.module-icon {
  color: #409eff;
  margin-bottom: 15px;
  transition: all 0.3s ease;
}

.action-module:hover .module-icon {
  color: #36cfc9;
  transform: scale(1.1);
}

.module-title {
  font-size: 17px;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 8px;
}

.module-subtitle {
  font-size: 13px;
  color: #7f8c8d;
  line-height: 1.4;
}

@media (max-width: 1200px) {
  .overview-section {
    flex-direction: column;
    gap: 25px;
  }

  .data-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .quick-actions-section {
    justify-content: center;
    gap: 20px;
  }
}

@media (max-width: 768px) {
  .home-container {
    padding: 20px;
  }

  .welcome-title {
    font-size: 24px;
  }

  .overview-section {
    margin-bottom: 30px;
  }

  .overview-panel {
    padding: 20px;
  }

  .data-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }

  .data-item {
    padding: 15px;
  }

  .data-value {
    font-size: 24px;
  }

  .quick-actions-section {
    gap: 15px;
  }

  .action-module {
    width: 160px;
    height: 120px;
    padding: 20px;
  }

  .module-title {
    font-size: 15px;
  }

  .module-subtitle {
    font-size: 12px;
  }
}
</style>
